import svgCaptcha from 'svg-captcha'
// import userModel from '../model/user'
import { setValue, getValue } from '../config/RedisConfig'
class PublicController {
  async getCaptcha (ctx) {
    const query = ctx.request.query
    const sid = query.sid
    const c = svgCaptcha.create({
      color: true,
      noise: Math.floor(Math.random() * 5)
    })
    // 设置redis时间为10分钟
    setValue(sid, c.text, 10 * 60)
    ctx.body = {
      code: 200,
      data: c.data
    }
  }

  async demo (ctx) {
    setValue('imooc', 'wwww')
    const res = await getValue('imooc')
    ctx.body = {
      res
    }
    // let data = new userModel({
    //   name: 'yiki',
    //   age: 30,
    //   email: '1111@qq.com',
    // })
    // ctx.body = await data.save()
  }
}

export default new PublicController()
